package com.bw.base.mvvm

import androidx.lifecycle.ViewModel
import com.bw.base.net.Apiservice
import com.bw.base.net.RetrofitUtils
import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody

open class BaseViewModel:ViewModel() {
    //将api实例化
    val apiservice=RetrofitUtils.getRetrofit().create(Apiservice::class.java)
    /**
     * 封装公共方法
     */
    fun mapToBody(map:MutableMap<String,Any>):RequestBody{
        var json = Gson().toJson(map)
        var body = RequestBody.create("application/json;charset=utf-8".toMediaType(), json)
        return body
    }
}